using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MySql.Data.MySqlClient;
using System.Data;

namespace MNNUTEM
{
    class crudProveedores
    {
        private Conexion cn = new Conexion();
        String query;
        private mensaje msj;

        public void Insert(TextBox id,TextBox rut, TextBox razon, TextBox ingreso, TextBox egreso, TextBox fono, TextBox mail, TextBox direccion)
        {

            try
            {


                

                //Console.Write(alt.GetType());

                query = "insert into proveedor (idProveedor,rutProveedor,razonProveedor,ingrsoProveedor,egresoProveedor,fonoProveedor,mailProveedor,Direccion_idDireccion,Llegada,Proveedore_has_Producto) values ('" + id.Text + "','" + rut.Text + "','" + razon.Text + "','" + ingreso.Text + "','" + egreso.Text + "','" + mail.Text + "','" + direccion.Text + ")";

                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                cn.conn().Close();
                msj = new mensaje("Producto Ingresado con éxito.", 1300, Color.Green);

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }



        }
        public void Delete(int ID)
        {

            try
            {
                query = "delete from Usuario where rutProveedor='" + ID + "'";
                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                cn.conn().Close();
                msj = new mensaje("Acción realizada con éxito.", 1300, Color.Green);

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }


        }
        private void Set()
        { }

        public DataTable Consultation(string consultation)
        {

            try
            {


                query = consultation;
                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = myCommand;
                DataTable dtable = new DataTable();
                sda.Fill(dtable);


                return dtable;

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }
        
        }



    }
}
